package com.onehouse.trigger.http;

import com.onehouse.domain.payment.service.IPaymentRequestService;
import com.onehouse.types.constants.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@CrossOrigin("*")
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private IPaymentRequestService paymentRequestService;

    @Operation(summary = "获取现金支付所需的信息", description = "现金支付只需要获取对应现金支付账单单号既可，支付宝支付还需要获取二维码")
    @GetMapping("/cash-payment-required-Info")
    public AjaxResult getCashPaymentRequiredInfo(@RequestParam("orderId") String orderId) {
        return AjaxResult.success(paymentRequestService.getCashPaymentRequiredInfo(orderId));
    }

    @Operation(summary = "现金支付申请")
    @PostMapping("/pay-cash-payment")
    public AjaxResult payCashPayment(@RequestParam("paymentId") String paymentId, @RequestParam("cashAmount") BigDecimal cashAmount) {
        // 如果现金收银系统是第三方的，在这里进行与第三方的支付，然后执行确实入账的确认逻辑
        return AjaxResult.success(paymentRequestService.handleCashPaymentPostEvent(paymentId, cashAmount));
    }

    @Operation(summary = "验证某个订单的是否被支付了逻辑")
    @GetMapping("/validate-order-payment-is-paid-off")
    public AjaxResult validateOrderPaymentIsPaidOff(@RequestParam String orderId) {
        return AjaxResult.success(paymentRequestService.validateOrderPaymentIsPaidOff(orderId));
    }

}
